#
#        Python GUI - Windows - Swing
#

from GWindows import Window as GWindow
from GContainers import Container as GContainer
import javax.swing as swing
import java.awt as awt

_default_options_for_style = {
    'standard':
        {'movable': 1, 'closable': 1, 'hidable': 1, 'resizable': 1},
    'nonmodal_dialog':
        {'movable': 1, 'closable': 0, 'hidable': 1, 'resizable': 0},
    'modal_dialog':
        {'movable': 1, 'closable': 0, 'hidable': 0, 'resizable': 0},
    'alert':
        {'movable': 1, 'closable': 0, 'hidable': 0, 'resizable': 0},
}

class Window(GWindow):
    def __init__(self,style='standard',zoomable=None, **kwds):
        self._style = style
        options = _default_options_for_style[self._style]
        for option in ['movable', 'closable', 'hidable', 'resizable']:
            if option in kwds.keys():
                options[option] = kwds[option]
                del kwds[option]
        
        self._j_obj=swing.JFrame()
        self._j_obj.setResizable(options['resizable'])
        if not options['closable']:
            #I wish I could do better here; this makes the close button do nothing, but the close button is still there
            self._j_obj.setDefaultCloseOperation(swing.JFrame.DO_NOTHING_ON_CLOSE)
        #No support for 'moveable' or 'hideable'
        
        self._j_obj.getContentPane().setLayout(None)
        
        GWindow.__init__(self,style,closable=options['closable'],_j_view=self._j_obj,**kwds)
    
    def set_title(self,title):
        self._j_obj.setTitle(title)
    
    def get_title(self):
        return self._j_obj.getTitle()
    
    def _add(self,comp):
        self._j_obj.getContentPane().add(comp._j_obj)
        self._j_obj.repaint(1000,0,0,self.width,self.height)
        GContainer._add(self,comp)
    
    def _remove(self,comp):
        self._j_obj.getContentPane().remove(comp._j_obj)
        GContainer._remove(self,comp)
    
    def bring_to_front(self):
        self._j_obj.toFront()
    
    def bring_to_back(self):
        self._j_obj.toBack()
    
    def destroy(self):
        self._j_obj.dispose()
        GWindow.destroy(self)